
$(function() {
		
	$("#from_s:visible").autocomplete(Test.emp);
		
	$("#to_s:visible").autocomplete(Test.emp);	
});

var Notice = {
	popup: function (e, p2, id) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);

		var c1 = 'log.php?do=Notice.edit&id=' + id;	
		var c2 = 'log.php?do=Notice.view&id=' + id;
		
		var c3 = 'log.php?do=Notice.send&id=' + id;
		var c4 = 'log.php?do=Notice.send&id=' + id;

		var a1 = ['编辑信息', 'url', 'Notice.dialog_edit_', '650x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '650x400'];
		
		var a3 = ['发送邮件', 'url', 'Notice.dialog_send_', '650x400'];
		var a4 = ['重新发送', 'url', 'Notice.list_sendmail', '650x400'];

		var s = c1 + ", " + c2 + ", " + c3;

		return popup(e, [a1, a2, a3], s);	
	},
	
	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				body.from = form.from.value;
				body.to = form.to.value;
				body.subject = form.subject.value;
				body.content = form.content.value;
				body.status = form.status.value;

				$(this).dialog("close");
				
				var url = 'log.php?do=Notice.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	dialog_send_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"发送": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}

				var form = $("#form_edit")[0];

				var body = {};
				body.id = form.id.value;
				body.from = form.from.value;
				body.to = form.to.value;
				body.subject = form.subject.value;
				body.content = form.content.value;
				body.status = form.status.value;

				$(this).dialog("close");
				
				var url = 'log.php?do=Notice.sendPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					alert("发送成功！");
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	list_sendmail: function (url, view) {
		if (confirm("是否重新发送？")) {
			$.get(url, function(data) {
				alert("发送成功！");
			});
		}
	}
};
